package com.example.controller;

import com.example.model.AddBlogInfoParam;
import com.example.model.BlogInfoResponse;
import com.example.model.Result;
import com.example.model.UpBlogParam;
import com.example.service.BlogService;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: bjc
 * Date: 2025-07-31
 * Time: 21:43
 */
@Slf4j
@RequestMapping("/blog")
@RestController
public class BlogController {

    @Autowired
    private BlogService blogService;
    /**
     * 获取博客列表
     * @return
     */
    @GetMapping("/getList")
    public List<BlogInfoResponse> getList() {
        return blogService.getList();
    }
    /**
     * 获取博客详情
     * @param blogId
     * @return
     */
    @GetMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull(message = "blogId不能为空") Integer blogId) {
        log.info("获取博客详情，blogId:{}", blogId);
        return blogService.getBlogDetail(blogId);
    }
    /**
     * 添加博客
     */
    @RequestMapping("/add")
    public Result<Boolean> addBlog(@Validated @RequestBody AddBlogInfoParam addBlogInfoParam){
        log.info("addBlog 接收参数："+addBlogInfoParam);
        return Result.success(blogService.addBlog(addBlogInfoParam));
    }
    /**
     * 更新博客
     */
    @RequestMapping("/update")
    public Boolean updateBlog(@Validated @RequestBody UpBlogParam upBlogParam){
        log.info("updateBlog 接收参数："+upBlogParam);
        return blogService.updateBlog(upBlogParam);
    }
    /**
     * 删除博客
     */
    @RequestMapping("/delete")
    public Boolean deleteBlog(@NotNull(message = "blogId不能为空") Integer blogId){
        log.info("deleteBlog 删除博客，blogId:{}", blogId);
        return blogService.deleteBlog(blogId);
    }
}
